<template>
  <el-row :gutter="40" class="panel-group">
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <div class="card-panel" @click="handleSetLineChartData('newVisitis')">
        <div class="card-panel-icon-wrapper icon-people">
          <svg-icon icon-class="peoples" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">人才库E力总和</div>
          <count-to :start-val="0" :end-val="statisticsData.ePower" :duration="1200" class="card-panel-num"/>
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <div class="card-panel" @click="handleSetLineChartData('messages')">
        <div class="card-panel-icon-wrapper icon-message">
          <svg-icon icon-class="message" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">昨日E豆收入</div>
          <count-to :start-val="0" :end-val="statisticsData.yestEbean" :duration="1400" class="card-panel-num"/>
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <div class="card-panel" @click="handleSetLineChartData('purchases')">
        <div class="card-panel-icon-wrapper icon-money">
          <svg-icon icon-class="money" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">当前E豆余额</div>
          <count-to :start-val="0" :end-val="statisticsData.balanceEbean" :duration="1600" class="card-panel-num"/>
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col" v-if="pdata.date">
      <div class="card-panel" @click="handleSetLineChartData('shoppings')">
        <div class="card-panel-icon-wrapper icon-shopping">
          <svg-icon icon-class="shopping" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">会员到期时间</div>
          <span class="card-panel-num">{{company.memberExpirationTime ? company.memberExpirationTime : '-'}}</span>
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col" v-if="getRouter !== '/setting/account'">
      <div class="card-panel" @click="handlego()">
        <div class="card-panel-icon-wrapper icon-shopping">
          <svg-icon icon-class="plus" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">新增人才</div>
          <count-to :start-val="0" :end-val="statisticsData.newTalent" :duration="1600" class="card-panel-num"/>
        </div>
      </div>
    </el-col>
    <!-- <el-col :xs="12" :sm="12" :lg="6"  class="card-panel-col" v-if="pdata.link">
      <div class="card-panel" @click="handlego()">
        <div class="card-panel-icon-wrapper icon-shopping">
          <svg-icon icon-class="plus" class-name="card-panel-icon" />
        </div>
        <div style="card-panel-description">
          <div class="card-panel-text">新增人才</div>
          <count-to :start-val="0" :end-val="statisticsData.newTalent" :duration="1600" class="card-panel-num"/>
        </div>
      </div>
    </el-col> -->

  </el-row>
</template>

<script>
  import CountTo from 'vue-count-to'

  export default {
    components: {
      CountTo
    },
    data () {
      return {
        memberExpirationTime: '',
        statisticsData: {
          balanceEbean: 0,
          ePower: 0,
          newTalent: 0,
          yestEbean: 0
        },
        company: {}
      }
    },
    props:["pdata"],
    methods: {
      handleSetLineChartData(type) {
        this.$emit('handleSetLineChartData', type)
      },
      handlego(){
        if (this.company.authState === 1) {
          this.$emit('handlego')
        } else if (this.company.authState === 2) {
          this.$message.info('企业认证审核中，请等待审核结束后...')
        } else if (this.company.authState === 0) {
          this.$confirm('您暂未完成企业认证，请先认证？', '提示', {
            confirmButtonText: '前往认证',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.$router.push({path: '/setting/index'})
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消添加人才'
            });         
          })
        } else if (this.company.authState === -1) {
          this.$confirm('您提交的企业认证审核已被驳回，请重新认证？', '提示', {
            confirmButtonText: '重新认证',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.$router.push({path: '/setting/index'})
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消添加人才'
            });         
          })
        } else {
          this.$confirm('您暂未完成企业认证，请先认证？', '提示', {
            confirmButtonText: '前往认证',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.$router.push({path: '/setting/index'})
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消添加人才'
            });         
          })
        }
      }
    },
    created () {
      let type = 'surplus'
      if (this.$route.path === '/index/1') {
        type = 'surplus'
      } else if (this.$route.path === '/index/2') {
        type = 'own'
      }
      this.$fetch(`${this.$api.statistics}/${type}`).then(res => {
        this.statisticsData = {
          balanceEbean: res.data.balanceEbean,
          ePower: res.data.ePower,
          newTalent: res.data.newTalent,
          yestEbean: res.data.yestEbean,
        }
        this.company = res.data.company
      })
    },
    computed: {
      getRouter () {
        return this.$route.path
      }
    }
  }
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .panel-group {
    margin-top: 18px;
    text-align: right;
    .card-panel-col{
      margin-bottom: 32px;
    }
    .card-panel {
      height: 108px;
      cursor: pointer;
      font-size: 12px;
      position: relative;
      overflow: hidden;
      color: #666;
      background: #fff;
      box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
      border-color: rgba(0, 0, 0, .05);
      &:hover {
        .card-panel-icon-wrapper {
          color: #fff;
        }
        .icon-people {
          background: #40c9c6;
        }
        .icon-message {
          background: #36a3f7;
        }
        .icon-money {
          background: #f4516c;
        }
        .icon-shopping {
          background: #34bfa3
        }
      }
      .icon-people {
        color: #40c9c6;
      }
      .icon-message {
        color: #36a3f7;
      }
      .icon-money {
        color: #f4516c;
      }
      .icon-shopping {
        color: #34bfa3
      }
      .card-panel-icon-wrapper {
        float: left;
        margin: 14px 0 0 14px;
        padding: 16px;
        transition: all 0.38s ease-out;
        border-radius: 6px;
      }
      .card-panel-icon {
        float: left;
        font-size: 48px;
      }
      .card-panel-description {
        float: right;
        font-weight: bold;
        margin: 26px;
        margin-left: 0px;
        .card-panel-text {
          line-height: 18px;
          color: rgba(0, 0, 0, 0.45);
          font-size: 16px;
          margin-bottom: 12px;
        }
        .card-panel-num {
          font-size: 20px;
        }
      }
    }
  }
</style>
